<?php echo use_helper('Form'); ?>

<?php slot('coursesNav', 'active') ?>
<div id="wrapper">
	<?php include_partial('global/systemMessages')?>
	<div id="content">
	<!-- 
		<div id="location-bar">
			<form method="post" action="">
				<fieldset>
					<select>
						<option>Harvard</option>
					</select>
				</fieldset>
			</form>
			<ul class="breadcrumbs">
				<li class="first"><a href="#">Fall 2008</a> &#xBB;</li>
				<li><a href="#">Positive Psychology</a> &#xBB;</li>
				<li>Write Notes</li>
			</ul>
		</div>
	-->	
		<div id="main">
			<div class="main-heading">

				<?php include_component('ratings','show', array('obj'=>$note))?>			
				<h1>Lecture <?php echo $note->getNumber() ?>: <?php echo $note->getTopic()?></h1>
				<h2><?php echo $note->getCourse()->getSubject() ? $note->getCourse()->getSubject()->getName().":" : "" ?> <?php echo $note->getCourse()->getName() ?></h2>
					<p style="margin-top: 2px; margin-bottom:2px; float:left;"><?php  echo($note->getTags() ? '( '.$note->getTags().' )':'') ?> </p>
			</div>
			<div id="notes" class="notes">
				<?php if($sf_user->isAuthenticated() 
					&& ($note->getUserId() == $sf_user->getId() || $sf_user->isAdmin()
					|| $sf_user->isGroupAdmin($note->getGroupId())
					|| $sf_user->isGroupContributor($note->getGroupId()))): ?>
					<div style="text-align: right;">
						<?php echo link_to('Edit', 'notes/edit?id='.$note->getId())?> | 
						<?php echo link_to('History', 'notes/history?id='.$note->getId())?>
					</div>
				<?php endif ?>
				<p><?php echo $note->getText() ?></p>
			</div>
			<p class="writer">
				Written by 
				<?php echo $note->getUser()->getHlFullName() ?>				
			</p>

			<?php if(isset($version_id)) { ?>
			<h4><span>Revert to this version</span></h4>
			<p>
				<?php echo form_tag('notes/revert?id=' . $note->getId()); ?>
				<?php echo input_hidden_tag('version',$version_id); ?>

				<label>Please explain why you are making this change:</label>
				<br /><br />
				<?php echo input_tag('version_comment'); ?><br /><br />
				<?php echo submit_tag('Revert'); ?><br /><br />
				</form>
			</p>

				<?php if(!$terminal_version) { ?>
				<h4><span>Delete this version</span></h4>
				<p>
					<?php echo form_tag('notes/deleterevision?id=' . $note->getId()); ?>
					<?php echo input_hidden_tag('version',$version_id); ?>

					<label>Please explain why you are making this change:</label>
					<br /><br />
					<?php echo input_tag('version_comment'); ?><br /><br />
					<?php echo submit_tag('Delete'); ?><br /><br />
					</form>
				</p>
				<?php } ?>
			<?php } ?>
		<!-- 
			<div class="article-rating">
				<div class="btn_ratings">
					<ul class="star-rating">
						<li style="width: 60%;" class="current-rating">Currently 3/5 Stars.</li>
						<li>
							<a class="one-star" title="1 star out of 5" href="#">1</a>
						</li>
						<li>
							<a class="two-stars" title="2 stars out of 5" href="#">2</a>
						</li>
						<li>
							<a class="three-stars" title="3 stars out of 5" href="#">3</a>
						</li>
						<li>
							<a class="four-stars" title="4 stars out of 5" href="#">4</a>
						</li>
						<li>
							<a class="five-stars" title="5 stars out of 5" href="#">5</a>
						</li>
					</ul>
				</div>
			</div>-->
			
			
		<br/>
			<?php include_component('ratings', 'editor', array('type_id'=>$note->getId(), 'type'=>RatingPeer::NOTE_TYPE)) ?>
			
		</div>

                <? if ($sf_user->isAuthenticated() && $show_annotations) { 
		include_partial('annotations/annoEditor',
				array('owner' => $annotate_owner, 'title' => $annotate_title,
				      'owner_sig' => $annotate_owner_sig, 'user_sig' => $annotate_user_sig, 'isowner' => $annotate_isowner));
		} ?>
	
		<div id="sidebar">
			<?php include_component('courses', 'about', array('course_id' => $note->getCourseId()))?>		
		
			<?php include_component('notes', 'relatedGroups', array('course_id' => $note->getCourseId()))?>
			
			<?php include_component('notes', 'related', array('course_id' => $note->getCourseId()))?>

		</div>
	</div>
	
</div>



<script>

//rate a note given the rating element that was clicked on
function rateNote(element){

	value = $(element).html();
	type = $(element).parent().parent().next().val();
	type_id = $(element).parent().parent().next().next().val();

	
	$.ajax({
		type: "POST",
		url: "<?php echo url_for('ratings/update')?>",
		data: {value: value, type: type, type_id: type_id},
		success: function(data) {

			$(element).parent().parent().parent().fadeOut(
					1000,
					function(){
						$(element).parent().parent().parent().replaceWith(data);
			});
					
		}
	});
	
}



//bind all rate note links
function bindNoteRatings()
{

	$('.star-rating').children().children().click(
			function(){

			rateNote(this);
			return false;
			}
		);
}

			$(document).ready(
			function(){
				bindNoteRatings();
				
			}
);

</script>
